package com.hudomju.swipe.sample;

import com.hudomju.swipe.util.RippleUtil;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;

import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;

/**
 * 主页面
 */
public class MainAbility extends Ability implements Component.ClickedListener {
    private Button btnListView;
    private Button btnRecyclerView;

    @Override
    protected void onStart(Intent intent) {
        getWindow().setStatusBarColor(Color.rgb(185,53,40));
        getWindow().setStatusBarVisibility(Component.VISIBLE);

        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_main_ability);

        btnListView = (Button) findComponentById(ResourceTable.Id_btn_list_view);
        btnRecyclerView = (Button) findComponentById(ResourceTable.Id_btn_recycler_view);

        RippleUtil.setComponentClickListener(btnListView, this::onClick);
        RippleUtil.setComponentClickListener(btnRecyclerView, this::onClick);
    }

    /** Called from xml */
    public void onGoToListViewClicked() {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.hudomju.swipe.sample")
                .withAbilityName("com.hudomju.swipe.sample.ListViewAbility")
                .build();
        intent.setOperation(operation);
        startAbility(intent);
    }

    /** Called from xml */
    public void onGoToRecyclerViewClicked() {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.hudomju.swipe.sample")
                .withAbilityName("com.hudomju.swipe.sample.RecyclerViewAbility")
                .build();
        intent.setOperation(operation);
        startAbility(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn_list_view:
                onGoToListViewClicked();
                break;
            case ResourceTable.Id_btn_recycler_view:
                onGoToRecyclerViewClicked();
                break;
            default:
                break;
        }
    }
}
